@extends('admin.public.master')
@section('content')
    <div class="content-wrapper">
        <div class="content-wrapper-before"></div>
        <div class="content-header row">
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('attribute.attribute.index')}}"><h5 class="content-header-title">属性列表</h5></a>
            </div>
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('attribute.attribute.create')}}"><h5 class="content-header-title">添加属性</h5></a>
            </div>

        </div>
        <div class="content-body">
            <div class="card">
                <div class="card-body table-responsive">
                    <table class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>属性编号</th>
                            <th>属性名</th>
                            <th>父级属性</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($attrs as$k=> $attr)
                        <tr>
                            <td class="mr-auto mt-auto" scope="row">{{$attr->id}}</td>
                            <td class="mr-auto mt-auto">{{$attr->name}}</td>
                            <td class="mr-auto mt-auto">{{$attr->attributeFather?$attr->attributeFather->name:'顶级属性'}}</td>
                            <td class="mr-auto mt-auto">
                                <a href="{{route('attribute.attribute.edit',$attr)}}"><button type="button" class="btn btn-info ">编辑</button></a>
                                <button onclick="del(this)" type="button" class="btn btn-danger">删除</button>
                                <form action="{{route('attribute.attribute.destroy',$attr)}}" method="post">
                                    @csrf @method('DELETE')
                                </form>
                            </td>
                        </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection
@push('js')
    <script>
        function del(obj) {
            swal({
                title: '确定删除吗？',
                text: '你将无法恢复它！',
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: '确定删除！',
                cancelButtonText: '取消删除！',
                confirmButtonClass: 'btn btn-success',
                cancelButtonClass: 'btn btn-danger',
                buttonsStyling: false
            }).then(function(value) {
                if(value.value){
                $(obj).next('form').submit();
                }
            })

        }
    </script>
    @endpush
